package 慕课网.model;
public class Subject {
    private String subjectName;
    private String subjectNo;
    private int subjectLife;
    private Student[] myStudents;
    private int studentNum;
    public Subject(){

    }
    public Subject(String subjectName,String subjectNo,int subjectLife){
        this.setSubjectName(subjectName);
        this.setSubjectNo(subjectNo);
        this.setSubjectLife(subjectLife);
    }
    public Subject(String subjectName,String subjectNo,int subjectLife,Student mystudent[]){
        this.setSubjectName(subjectName);
        this.setSubjectNo(subjectNo);
        this.setSubjectLife(subjectLife);
        this.setMyStudents(mystudent);
    }

    public Student[] getMyStudents() {
        if(this.myStudents==null)
            this.myStudents=new Student[200];
        return myStudents;
    }

    public int getStudentNum() {
        return studentNum;
    }

    public void setStudentNum(int studentNum) {
        this.studentNum = studentNum;
    }

    public void setMyStudents(Student[] myStudents) {
        this.myStudents = myStudents;
    }

    public void setSubjectName(String subjectName) {
        this.subjectName = subjectName;
    }
    public void setSubjectNo(String subjectNo) {
        this.subjectNo = subjectNo;
    }
    public void setSubjectLife(int subjectLife) {
        if(subjectLife<=0)
        {
            return;
        }
        this.subjectLife = subjectLife;
    }
    public int getSubjectLife() {
        return subjectLife;
    }
    public String getSubjectName() {
        return subjectName;
    }
    public String getSubjectNo() {
        return subjectNo;
    }
    public String info(){
        String str="专业信息如下：\n专业名称："
                +this.getSubjectName()
                +"\n专业编号："+this.getSubjectNo()
                +"\n学制年限："+this.getSubjectLife()+"年";
        return str;
    }
    public void addStudent(Student stu){
        for(int i=0;i<this.getMyStudents().length;i++)
        {
            if(this.getMyStudents()[i]==null)
            {
                this.getMyStudents()[i]=stu;
                this.setStudentNum(i+1);
//                this.studentNum=i+1;
                return;
            }
        }
    }
}
